//
//  NvEditThemeViewController.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/6/12.
//  Copyright © 2018年 meishe. All rights reserved.
//

#import "NvEditThemeViewController.h"
#import "NvLiveWindowPanelView.h"
#import "NvFilterCell.h"
#import "NvMoreFilterViewController.h"
#import "NvAssetManager.h"
#import "NvAsset.h"
#import "NvCaptionThemeItem.h"
#import "NvThemeCell.h"
#import "NvTimelineData.h"
#import "NvTimelineUtils.h"
#import "NvsTimelineCaption.h"
#import "NvRectView.h"
#import "NvCaptionDialog.h"
#import "NvsTimeline.h"

@interface NvEditThemeViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, NvAssetManagerDelegate, NvLiveWindowPanelViewDelegate>

@property (nonatomic, strong) NvLiveWindowPanelView *liveWindowPanel;
@property (nonatomic, strong) NvsStreamingContext *streamingContext;

//主题，滤镜视图
@property (nonatomic, strong) UIView *themePanelView;//最外层视图
@property (nonatomic, strong) UICollectionView *themeCollectionView;//主题，滤镜滑动视图
@property (nonatomic, strong) NSMutableArray *themeDataSource;//主题，滤镜数组

@property (nonatomic, strong) NvAssetManager *assetManager;

@property (nonatomic, strong) NSMutableArray<NvMusicInfoModel *> *musicDataArray;//存储选择的音乐
@property(strong, nonatomic) NvThemeInfoModel *themeInfo;

@property(strong, nonatomic) NvRectView *rectView;
@property (nonatomic, strong) NvCaptionDialog *changeDialog;
@property (nonatomic, strong) NvsTimelineCaption *currentCaption;

@property (nonatomic, strong) UIView *line;

@end

@implementation NvEditThemeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.streamingContext = [NvsStreamingContext sharedInstance];
    [self initTimeline];
    [self addSubViews];
    self.musicDataArray = [NSMutableArray arrayWithArray: [[NvTimelineData sharedInstance] musicDataArray]];
    [_liveWindowPanel connectTimeline:_timeline];
    [self seekTimeline:0];
    
    self.assetManager = [NvAssetManager sharedInstance];
    self.assetManager.delegate = self;
    [self.assetManager searchLocalAssets:ASSET_THEME];
    [self getDefaultData];
    [self.liveWindowPanel hiddenVolumeButton];
    
    NSString *itemPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"theme"];
    [self.assetManager searchReservedAssets:ASSET_THEME bundlePath:itemPath];
}

- (UIView *)leftNavigationBarItemView {
    return [UIView new];
}

- (void)initReservedAssetName:(NvAsset *)asset {
    if ([asset isReserved]) {
        if ([asset.uuid isEqualToString:@"924EDA33-8FDF-435B-9DDE-414F9D07CB84"]) {
            asset.name = @"简约方格";
        }
    }
}

- (void)initTimeline {
    self.timeline = [NvTimelineUtils createTimeline:self.editMode];
    [NvTimelineUtils recreateTimeline:self.timeline];
    self.themeInfo = [[NvTimelineData sharedInstance].themeInfo copy];
}

- (void)dealloc {
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self connectLiveWindow];
    [self getDefaultData];
    [_themeCollectionView reloadData];
}
//获取默认数据
- (void)getDefaultData {
    NSString *themeId = [self.timeline getCurrentThemeId];
    AspectRatio ratio;
    switch (self.editMode) {
        case NvEditMode16v9:
            ratio = AspectRatio_16v9;
            break;
        case NvEditMode1v1:
            ratio = AspectRatio_1v1;
            break;
        case NvEditMode9v16:
            ratio = AspectRatio_9v16;
            break;
        case NvEditMode3v4:
            ratio = AspectRatio_3v4;
            break;
        case NvEditMode4v3:
            ratio = AspectRatio_4v3;
            break;
        default:
            ratio = AspectRatio_All;
            break;
    }
    NSArray *array = [self.assetManager getUsableAssets:ASSET_THEME aspectRatio:ratio categoryId:NV_CATEGORY_ID_ALL];
    self.themeDataSource = [NSMutableArray array];
    for (NvAsset *asset in array) {
        NvCaptionThemeItem *item = [NvCaptionThemeItem new];
        item.imageUrl = [asset.coverUrl absoluteString];
        [self initReservedAssetName:asset];
        item.name = asset.name;
        item.packageId = asset.uuid;
        item.isInstall = asset.isInstallingFinished;
        if ([item.packageId isEqualToString:themeId]) {
            item.isSelect = YES;
        } else {
            item.isSelect = NO;
        }
        [self.themeDataSource addObject:item];
    }
    NvCaptionThemeItem *item = [NvCaptionThemeItem new];
    item.imageUrl = @"NvsFilterNone";
    item.name = @"无";
    item.packageId = @"";
    item.isInstall = YES;
    if (!themeId || [themeId isEqualToString:@""]) {
        item.isSelect = YES;
    } else {
        item.isSelect = NO;
    }
    [self.themeDataSource insertObject:item atIndex:0];

}

- (void)connectLiveWindow {
    [_liveWindowPanel connectTimeline:_timeline];
    [self seekTimeline:_liveWindowPanel.currentTime];
}

- (void)addSubViews{
    if (KIsiPhoneX) {
        self.themePanelView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGTH - 137*SCREANSCALE - 34 - NV_STATUSBARHEIGHT - NV_NAV_BAR_HEIGHT, SCREEN_WDITH, 137*SCREANSCALE + 34)];
    }else{
        self.themePanelView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGTH - 137*SCREANSCALE - 34 - NV_STATUSBARHEIGHT, SCREEN_WDITH, 137*SCREANSCALE + 34)];
    }
    self.liveWindowPanel = [[NvLiveWindowPanelView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.width)];
    self.liveWindowPanel.delegate = self;
    _liveWindowPanel.editMode = self.editMode;
    [self.view addSubview:_liveWindowPanel];
    self.rectView = [[NvRectView alloc] initWithFrame:self.liveWindowPanel.bounds type:NV_CAPTION];
    [self.rectView hiddenAllImage];
    self.rectView.delegate = self;
    [self.liveWindowPanel.liveWindow addSubview:self.rectView];
    [self.liveWindowPanel.controlPanelView bringSubviewToFront:self.liveWindowPanel];
    [self.view addSubview:_themePanelView];
    
    [self.rectView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapScreen)]];
    
    UIButton *moreB = [UIButton buttonWithType:UIButtonTypeCustom];
    moreB.tag = 1101;
    [moreB setImage:[NvUtils imageWithName:@"NvsFilterMore"] forState:UIControlStateNormal];
    moreB.frame = CGRectMake(13 * SCREANSCALE, 23 * SCREANSCALE, 35 * SCREANSCALE, 25 * SCREANSCALE);
    [_themePanelView addSubview:moreB];
    [moreB addTarget:self action:@selector(moreClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *moreL = [[UILabel alloc]initWithFrame:CGRectMake(20 * SCREANSCALE, moreB.frame.origin.y + moreB.frame.size.height + 15, 30 * SCREANSCALE, 21 * SCREANSCALE)];
    moreL.text = @"更多";
    moreL.textColor = [UIColor nv_colorWithHexARGB:@"#CCFFFFFF"];
    moreL.font = [NvUtils regularFontWithSize:11];
    [_themePanelView addSubview:moreL];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake(49*SCREANSCALE, 70*SCREANSCALE);
    layout.minimumLineSpacing = 10*SCREANSCALE;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 16*SCREANSCALE, 0, 0);
    _themeCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(60 * SCREANSCALE, 0, SCREEN_WDITH - 60 * SCREANSCALE, 85*SCREANSCALE) collectionViewLayout:layout];
    _themeCollectionView.delegate = self;
    _themeCollectionView.dataSource = self;
    _themeCollectionView.backgroundColor = UIColorFromRGB(0x242728);
    _themeCollectionView.showsHorizontalScrollIndicator = NO;
    [_themePanelView addSubview:_themeCollectionView];
    [_themeCollectionView registerClass:[NvThemeCell class] forCellWithReuseIdentifier:@"NvThemeCell"];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(13*SCREANSCALE,_themePanelView.top - 17*SCREANSCALE,280*SCREANSCALE,17*SCREANSCALE);
    label.numberOfLines = 0;
    label.textColor = UIColor.whiteColor;
    label.alpha = 0.6;
    label.font = [NvUtils regularFontWithSize:12];
    label.text = @"片头处暂停可以修改文字";
    [self.view addSubview:label];
    
    UIButton *finshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [finshBtn setImage:[NvUtils imageWithName:@"Nvcheck - material"] forState:UIControlStateNormal];
    finshBtn.frame = CGRectMake(175 * SCREANSCALE, 102 *SCREANSCALE, 25 * SCREANSCALE, 20 * SCREANSCALE);
    [finshBtn addTarget:self action:@selector(finshClick:) forControlEvents:UIControlEventTouchUpInside];
    [_themePanelView addSubview:finshBtn];
    
    self.line = [UIView new];
    self.line.backgroundColor = [UIColor nv_colorWithHexARGB:@"#1AFFFFFF"];
    [self.view addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@1);
        make.bottom.equalTo(finshBtn.mas_top).offset(-12*SCREANSCALE);
    }];
}

- (void)singleTapScreen {
    
}
     
- (void)finshClick:(UIButton *)sender{
    [self.streamingContext removeTimeline:self.timeline];
    NvTimelineData *data = [NvTimelineData sharedInstance];
    data.themeInfo = self.themeInfo;
    NSMutableArray *order = [[NvTimelineData sharedInstance] dataOrder];
    [order removeObject:@"Theme"];
    [order addObject:@"Theme"];
    
    [self.navigationController popViewControllerAnimated:YES];
}

// 定位某一时间戳的图像
- (void)seekTimeline:(int64_t)postion {
    if (![_streamingContext seekTimeline:_timeline timestamp:postion videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:NvsStreamingEngineSeekFlag_ShowCaptionPoster | NvsStreamingEngineSeekFlag_ShowAnimatedStickerPoster])
        NSLog(@"定位时间线失败！");
}

//更新字幕框的位置
- (void)updateCaptionView: (NvsTimelineCaption*) caption {
    NSArray *array = [caption getBoundingRectangleVertices];
    NSValue *leftTopValue = array[0];
    NSValue *leftBottomValue = array[1];
    NSValue *rightBottomValue = array[2];
    NSValue *rightTopValue = array[3];
    CGPoint topLeftCorner = [leftTopValue CGPointValue];
    CGPoint bottomLeftCorner = [leftBottomValue CGPointValue];
    CGPoint rightBottomCorner = [rightBottomValue CGPointValue];
    CGPoint rightTopCorner = [rightTopValue CGPointValue];
    
    topLeftCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:topLeftCorner];
    rightBottomCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:rightBottomCorner];
    bottomLeftCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:bottomLeftCorner];
    rightTopCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:rightTopCorner];
    
    [self.rectView setPoints:@[[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:topLeftCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:bottomLeftCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:rightBottomCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:rightTopCorner toView:self.rectView]]]];
    if ([caption getTextAlignment] == NvsTextAlignmentLeft) {
        [self.rectView setTextAlign:NvLeft];
    } else if ([caption getTextAlignment] == NvsTextAlignmentCenter) {
        [self.rectView setTextAlign:NvCenter];
    } else if ([caption getTextAlignment] == NvsTextAlignmentRight) {
        [self.rectView setTextAlign:NvRight];
    }
    
    [_streamingContext seekTimeline:self.timeline timestamp:[_streamingContext getTimelineCurrentPosition:self.timeline] videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:0];
}

- (void)sliderValueChanged:(float)value {
    ino64_t currentTime = self.timeline.duration*value;
    [_streamingContext seekTimeline:self.timeline timestamp:currentTime videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:0];
    NSArray *captionarray = [self.timeline getCaptionsByTimelinePosition:[_streamingContext getTimelineCurrentPosition:self.timeline]];
    NvsTimelineCaption *caption = [self removeThemeCaption:captionarray].firstObject;
    self.currentCaption = caption;
    [self updateCaptionView:self.currentCaption];
}

- (void)didStreamingEngineStateChanged:(NvsStreamingEngineState)state {
    if (state == NvsStreamingEngineState_Playback) {
        self.rectView.hidden = YES;
    } else {
        NSArray *captionarray = [self.timeline getCaptionsByTimelinePosition:[_streamingContext getTimelineCurrentPosition:self.timeline]];
        NvsTimelineCaption *caption = [self removeThemeCaption:captionarray].firstObject;
        self.currentCaption = caption;
        if (self.currentCaption) {
            self.rectView.hidden = NO;
        }
        [self updateCaptionView:caption];
    }
}

- (void)rectView:(NvRectView *)rectView touchBeganPoint:(CGPoint)point {
    NSArray *captionarray = [self.timeline getCaptionsByTimelinePosition:[_streamingContext getTimelineCurrentPosition:self.timeline]];
    NvsTimelineCaption *caption = [self removeThemeCaption:captionarray].firstObject;
    self.currentCaption = caption;
    if (self.currentCaption) {
        NSArray *array = [caption getBoundingRectangleVertices];
        NSValue *leftTopValue = array[0];
        NSValue *leftBottomValue = array[1];
        NSValue *rightBottomValue = array[2];
        NSValue *rightTopValue = array[3];
        CGPoint topLeftCorner = [leftTopValue CGPointValue];
        CGPoint bottomLeftCorner = [leftBottomValue CGPointValue];
        CGPoint rightBottomCorner = [rightBottomValue CGPointValue];
        CGPoint rightTopCorner = [rightTopValue CGPointValue];
        
        topLeftCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:topLeftCorner];
        rightBottomCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:rightBottomCorner];
        bottomLeftCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:bottomLeftCorner];
        rightTopCorner = [self.liveWindowPanel.liveWindow mapCanonicalToView:rightTopCorner];
        
        CGMutablePathRef pathRef=CGPathCreateMutable();
        CGPathMoveToPoint(pathRef, NULL, topLeftCorner.x, topLeftCorner.y);
        CGPathAddLineToPoint(pathRef, NULL, bottomLeftCorner.x, bottomLeftCorner.y);
        CGPathAddLineToPoint(pathRef, NULL, rightBottomCorner.x, rightBottomCorner.y);
        CGPathAddLineToPoint(pathRef, NULL, rightTopCorner.x, rightTopCorner.y);
        CGPathCloseSubpath(pathRef);
        bool isIn = CGPathContainsPoint(pathRef, nil, point, false);
        CGPathRelease(pathRef);
        if(isIn){
            [self.rectView setPoints:@[[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:topLeftCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:bottomLeftCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:rightBottomCorner toView:self.rectView]],[NSValue valueWithCGPoint:[self.liveWindowPanel.liveWindow convertPoint:rightTopCorner toView:self.rectView]]]];
            NSLog(@"在内部");
            self.changeDialog = [[[NSBundle mainBundle] loadNibNamed:@"CaptionDialog" owner:self options:nil] firstObject];
            [self.changeDialog setCaptionText:[caption getText]];
            [self.view addSubview:self.changeDialog];
            self.changeDialog.delegate = self;
            [self.changeDialog mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view);
                make.top.equalTo(@(80*SCREANSCALE));
                make.width.equalTo(@(320*SCREANSCALE));
                make.height.equalTo(@(180*SCREANSCALE));
            }];
        } else {
            if (self.liveWindowPanel.controlPanelView.hidden == YES) {
                [self.liveWindowPanel showControllPanel];
            } else {
                [self.liveWindowPanel playAtTime:[_streamingContext getTimelineCurrentPosition:self.timeline]];
            }
        }
    } else {
        if (self.liveWindowPanel.controlPanelView.hidden == YES) {
            [self.liveWindowPanel showControllPanel];
        } else {
            [self.liveWindowPanel playAtTime:[_streamingContext getTimelineCurrentPosition:self.timeline]];
        }
    }
}

// MARK: NvCaptionDialogDelegate
- (void)captionDialog:(NvCaptionDialog *)captionDialog clickButtonIndex:(NSInteger)index {
    //添加字幕页面修改字幕
    if (self.changeDialog == captionDialog) {
        if (index == 0) {
            NSString* text = [captionDialog getCaptionText];
            text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            self.themeInfo.isChange = YES;
            [self.timeline setThemeTitleCaptionText:text];
            self.themeInfo.themeString = text;
            [self.timeline applyTheme:self.themeInfo.themeName];
            [_streamingContext seekTimeline:self.timeline timestamp:[_streamingContext getTimelineCurrentPosition:self.timeline] videoSizeMode:NvsVideoPreviewSizeModeFullSize flags:0];
            [self updateCaptionView:self.currentCaption];
        } else {
            //不做处理
        }
        [self.changeDialog removeFromSuperview];
        self.changeDialog = nil;
    }
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.themeDataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NvThemeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NvThemeCell" forIndexPath:indexPath];
    [cell renderCellWithItem:self.themeDataSource[indexPath.row]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NvCaptionThemeItem *currentItem = self.themeDataSource[indexPath.row];
    if (!currentItem.isInstall) {
        return;
    }
    for (NvCaptionThemeItem *item in self.themeDataSource) {
        item.isSelect = NO;
    }
    
    NvCaptionThemeItem *item = self.themeDataSource[indexPath.row];
    item.isSelect = YES;
    NvThemeCell *cell = (NvThemeCell *)[collectionView cellForItemAtIndexPath:indexPath];
    [cell renderCellWithItem:item];
    [_themeCollectionView reloadData];
    
    self.themeInfo = NvThemeInfoModel.new;
    self.themeInfo.themeName = item.packageId;
    NvTimelineData *timelineData = [NvTimelineData sharedInstance];
    timelineData.themeInfo = self.themeInfo;
    
    if (indexPath.row == 0) {
        self.themeInfo = nil;
        NSMutableArray *musicData = [NSMutableArray arrayWithArray:self.musicDataArray];
        [[NvTimelineData sharedInstance] setMusicDataArray:musicData];
        [NvTimelineUtils resetMusicTrack:self.timeline musicDataArray:musicData];
    } else {
        NSMutableArray *musicData = NSMutableArray.new;
        [[NvTimelineData sharedInstance] setMusicDataArray:musicData];
        [NvTimelineUtils resetMusicTrack:self.timeline musicDataArray:musicData];
    }
    
    [NvTimelineUtils resetTheme:self.timeline themeInfo:self.themeInfo];
    [NvTimelineUtils resetCaption:self.timeline captionDataArray:timelineData.captionDataArray];
    
    [self addThemeText];
    
    //更改播放器的总时间
    [_liveWindowPanel connectTimeline:_timeline];
    [self.liveWindowPanel playAtTime:0];
}

#pragma mark 给主题model添加主题字幕信息
- (void)addThemeText{
    NvsTimelineCaption* caption = [self.timeline getFirstCaption];
    while (caption) {
        if (caption.category == NvsThemeCategory && caption.roleInTheme != NvsRoleInThemeGeneral) {
            NSLog(@"%d,%d,%@",caption.category,caption.roleInTheme,caption.getText);
            self.themeInfo.themeString = [caption getText];
            self.themeInfo.thenmeRoleInTheme = caption.roleInTheme;
            if (!self.themeInfo.isChange) {
                self.themeInfo.themeString = @"美摄-记录美好生活";
                [self.timeline setThemeTitleCaptionText:self.themeInfo.themeString];
                [self.timeline applyTheme:self.themeInfo.themeName];
            }
            
            break;
        }else{
            //不处理
        }
        caption = [self.timeline getNextCaption:caption];
    }
}

- (void)removeAllThemeCaption {
    NSMutableArray *themeArray = [NSMutableArray array];
    for (NvCaptionInfoModel *captionModel in [[NvTimelineData sharedInstance] captionDataArray]) {
        if (captionModel.category == NvsThemeCategory && captionModel.roleInTheme == NvsRoleInThemeGeneral) {
            [themeArray addObject:captionModel];
        }
    }
    [[[NvTimelineData sharedInstance] captionDataArray] removeObjectsInArray:themeArray];
}

#pragma mark NvAssetManagerDelegate
//安装完成的回调
- (void)onFinishAssetPackageInstallation:(NSString *)uuid {
    NSLog(@"-------%@",uuid);
}

#pragma mark 更多按钮点击
- (void)moreClick:(UIButton *)sender{
    NvMoreFilterViewController *vc = [[NvMoreFilterViewController alloc]init];
    vc.editModel = self.editMode;
    vc.type = ASSET_THEME;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setCurrentCaption:(NvsTimelineCaption *)currentCaption{
    if (currentCaption.category == NvsThemeCategory && currentCaption.roleInTheme != NvsRoleInThemeGeneral) {
        _currentCaption = currentCaption;
    }else{
        _currentCaption = nil;
    }
}

- (NSArray *)removeThemeCaption:(NSArray *)captionArray {
    NSMutableArray *array = [NSMutableArray array];
    [captionArray enumerateObjectsUsingBlock:^(NvsTimelineCaption*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj.category == NvsThemeCategory && obj.roleInTheme != NvsRoleInThemeGeneral) {
            [array addObject:obj];
        } else {
            
        }
    }];
    return [array copy];
}

@end
